package com.eonmind.knowledge.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Author: AKang
 * @Description:
 * @CreateTime: 2025-06-05
 */
@Configuration
public class UploadTaskPoolsConfig {
    /**
     * 文件上传线程池
     *
     * @return ThreadPoolTaskExecutor
     */
    @Bean("uploadTaskExecutor")
    public ThreadPoolTaskExecutor uploadTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(10);
        executor.setMaxPoolSize(20);
        executor.setQueueCapacity(200);
        executor.setThreadNamePrefix("file-upload-executor-");
        executor.setKeepAliveSeconds(60);
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setAwaitTerminationSeconds(180);
        executor.setAllowCoreThreadTimeOut(true);
        executor.setThreadGroupName("fileUpload");
        executor.initialize();
        return executor;
    }

}
